<?php

namespace App\Models;

class Company extends Model
{
    protected $fillable = ['area_id', 'name', 'logo', 'introduction', 'remark', 'forbidden', 'delflag'];

    public function area()
    {
        return $this->belongsTo(Area::class, 'area_id');
    }

    public function categories()
    {
        return $this->belongsToMany(Category::class, 'company_categories', 'company_id', 'category_id');
    }

    public function users()
    {
        return $this->belongsToMany(User::class, 'company_users', 'company_id', 'user_id');
    }

    public function filiales()
    {
        return $this->hasMany(Filiale::class, 'company_id');
    }

    public function products()
    {
        return $this->hasMany(Product::class, 'company_id');
    }

    public function prizes()
    {
        return $this->hasManyThrough(Prize::class, Product::class);
    }

    public function isOwnerOf($model)
    {
        return $this->id == $model->company_id;
    }
}
